home *** CD-ROM | disk | FTP | other *** search
- Path: ernie.idi.oclc.org!usenet
- From: Ron Unterreiner <runterreiner@idi.oclc.org>
- Newsgroups: comp.lang.c++
- Subject: Re: No struct in C++!!?
- Date: Thu, 15 Feb 1996 08:23:40 -0800
- Organization: Information Dimensions, Inc.
- Message-ID: <31235E0C.252C@idi.oclc.org>
- References: <1996Feb14.151620.5532@queens-belfast.ac.uk>
- NNTP-Posting-Host: runterr.idi.oclc.org
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (Win16; I)
-
- Georg Woste wrote:
- >
- > Hi,
- >
- > a beginners question: I found in different C++ books examples of C++ programms
- > which contain type declarations and definitions in the main() programm - for
- > example a struct - as in C.
- > My question is, whether this is a contradiction
- > to the paradigm of C++. Shouldn't be everything in a C++ programm
- > either classes, objects or the interaction between objects?
- > So is it bad C++ style, to use functions or data outside from
- > classes (objects)?
- >
- > Thanks!
- >
- > Georg Woeste
-
- A class is a struct. Anywhere you see the word struct you can substitute
- the word class. The major thing a class gives you that a C struct
- doesn't is the ability to protect data. You can control the way the data
- in the class is accessed from outside by writing methods. It works much
- like stacks and queues where you would define AddMember, DeleteMember and
- TraverseMember functions. In a nutshell, a class is a really powerful
- struct. You can define a class like a C struct though by making all your
- data public. This is usually a bad idea because the data in the class
- could get stepped on accidently if you are not careful. The whole
- purpose of classes is to restrict access to the data inside.
-